package com.mysql.bean;

import com.mysql.factory.PropertiesFactory;

import java.io.IOException;

public final class GlobleConfig {

    // 配置信息
    private volatile static ConfigurationInfo CONFIGURATION_INFO = null;

    /***
     * 获取全局配置
     * 单例模式 双重锁校验
     */
    public static ConfigurationInfo getGlobleConfig() {
        if (null == CONFIGURATION_INFO) {
            synchronized (GlobleConfig.class) {
                if (null == CONFIGURATION_INFO) {
                    try {
                        PropertiesFactory.loadProperties();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
        return CONFIGURATION_INFO;
    }

    public static void setGlobleConfig(ConfigurationInfo configurationInfo) {
        GlobleConfig.CONFIGURATION_INFO = configurationInfo;
    }

    private GlobleConfig() {}
}
